/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VentanaAlimentacion.java
 *
 * Created on 01/09/2009, 11:35:28 AM
 */

package ac.view;

import ac.entities.Alimento;
import ac.entities.Animal;
import ac.entities.EspDie;
import ac.entities.Especie;
import ac.entities.FechaAli;
import ac.entities.Grupo;
import ac.entities.LoFe;
import ac.entities.Lote;
import ac.entities.Tanque;
import ac.persistence.PersistEspecie;
import ac.persistence.PersistTanque;
import ac.persistence.PersistenceFreddy;
import java.util.ArrayList;
import java.util.Date;
import javax.swing.DefaultListModel;

/**
 *
 * @author freddy
 */
public class VentanaAlimentacion extends javax.swing.JFrame {

    PersistTanque persistTanque = new PersistTanque();
    PersistenceFreddy persistFreddy = new PersistenceFreddy();
    PersistEspecie persistEspecie = new PersistEspecie();
    ArrayList<Tanque> tanques =null;
    ArrayList<Grupo> grupos =null;
    ArrayList<Alimento> alimentos =null;
    ArrayList<Alimento> alimentosG =null;
    ArrayList<Animal> animales = null;
    ArrayList<Especie> especies = null;
    ArrayList<Lote> lotes = null;
    ArrayList<Lote> lotesG = null;
    DefaultListModel modeloTanques = new DefaultListModel();
    DefaultListModel modeloAlimentos = new DefaultListModel();
    DefaultListModel modeloAlimentosG = new DefaultListModel();
    DefaultListModel modeloIndividuos = new DefaultListModel();
    DefaultListModel modeloGrupos = new DefaultListModel();
    int tanqueSeleccionado;
    int animalSeleccionado;
    int alimentoSeleccionado;
    int alimentoGSeleccionado;
    int grupoSeleccionado;
    int especieSeleccionada;
    EspDie espdie = null;
    EspDie espdieG = null;

    /** Creates new form VentanaAlimentacion */
    public VentanaAlimentacion() {
        LookAndFeel look = new LookAndFeel();
        initComponents();
        cargarTanques();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        dialogAlimento = new javax.swing.JDialog();
        dialogAlimentoG = new javax.swing.JDialog();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        listaIndividuos = new javax.swing.JList();
        jLabel2 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jScrollPane4 = new javax.swing.JScrollPane();
        listaAlimentos = new javax.swing.JList();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        campoVecesDia = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        campoFrecuencia = new javax.swing.JTextField();
        campoDia = new javax.swing.JTextField();
        campoHoraAnimal = new javax.swing.JTextField();
        jScrollPane6 = new javax.swing.JScrollPane();
        areaCantidad = new javax.swing.JTextArea();
        botonAlimentarAnimal = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        listaTanques = new javax.swing.JList();
        jLabel1 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        listaGrupos = new javax.swing.JList();
        jLabel3 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jLabel11 = new javax.swing.JLabel();
        campoDiaG = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jTextField7 = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jSeparator2 = new javax.swing.JSeparator();
        jScrollPane5 = new javax.swing.JScrollPane();
        listaAlimentosG = new javax.swing.JList();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        campoVecesDiaG = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        campoFrecuenciaG = new javax.swing.JTextField();
        botonAlimentarGrupo = new javax.swing.JButton();
        jScrollPane7 = new javax.swing.JScrollPane();
        areaCantidadG = new javax.swing.JTextArea();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();
        jLabel18 = new javax.swing.JLabel();
        campoUbicacion = new javax.swing.JTextField();
        jLabel19 = new javax.swing.JLabel();
        campoMaterial = new javax.swing.JTextField();
        jLabel20 = new javax.swing.JLabel();
        campoCapacidad = new javax.swing.JTextField();

        javax.swing.GroupLayout dialogAlimentoLayout = new javax.swing.GroupLayout(dialogAlimento.getContentPane());
        dialogAlimento.getContentPane().setLayout(dialogAlimentoLayout);
        dialogAlimentoLayout.setHorizontalGroup(
            dialogAlimentoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 484, Short.MAX_VALUE)
        );
        dialogAlimentoLayout.setVerticalGroup(
            dialogAlimentoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 366, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout dialogAlimentoGLayout = new javax.swing.GroupLayout(dialogAlimentoG.getContentPane());
        dialogAlimentoG.getContentPane().setLayout(dialogAlimentoGLayout);
        dialogAlimentoGLayout.setHorizontalGroup(
            dialogAlimentoGLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        dialogAlimentoGLayout.setVerticalGroup(
            dialogAlimentoGLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        listaIndividuos.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                listaIndividuosMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(listaIndividuos);

        jLabel2.setText("Individuos:");

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Alimentacion"));

        jLabel4.setText("Dia:");

        jLabel5.setText("Hora:");

        jLabel6.setText("Ultima");

        jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);

        listaAlimentos.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                listaAlimentosMouseClicked(evt);
            }
        });
        jScrollPane4.setViewportView(listaAlimentos);

        jLabel7.setText("Alimentos:");

        jLabel8.setText("Cantidad:");

        jLabel9.setText("Veces al dia:");

        jLabel10.setText("Frecuencia:");

        areaCantidad.setColumns(20);
        areaCantidad.setRows(5);
        jScrollPane6.setViewportView(areaCantidad);

        botonAlimentarAnimal.setText("Alimentar");
        botonAlimentarAnimal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonAlimentarAnimalActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addGap(10, 10, 10)
                                .addComponent(campoDia, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(campoHoraAnimal))))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(96, 96, 96)
                        .addComponent(jLabel6)))
                .addGap(37, 37, 37)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(43, 43, 43)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addComponent(jLabel8)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addComponent(jLabel10)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(campoFrecuencia, javax.swing.GroupLayout.DEFAULT_SIZE, 151, Short.MAX_VALUE))
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addComponent(jLabel9)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(campoVecesDia, javax.swing.GroupLayout.DEFAULT_SIZE, 153, Short.MAX_VALUE))))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addComponent(botonAlimentarAnimal)))))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel2Layout.createSequentialGroup()
                            .addGap(22, 22, 22)
                            .addComponent(jLabel6)
                            .addGap(18, 18, 18)
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel4)
                                .addComponent(campoDia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(18, 18, 18)
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel5)
                                .addComponent(campoHoraAnimal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel9)
                                    .addComponent(campoVecesDia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel10)
                                    .addComponent(campoFrecuencia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel8)
                                    .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(botonAlimentarAnimal))
                            .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE))))
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addGap(202, 202, 202)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(22, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        listaTanques.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                listaTanquesMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(listaTanques);

        jLabel1.setText("Tanques:");

        jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        listaGrupos.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                listaGruposMouseClicked(evt);
            }
        });
        jScrollPane3.setViewportView(listaGrupos);

        jLabel3.setText("Grupos:");

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Alimentacion"));

        jLabel11.setText("Dia:");

        campoDiaG.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                campoDiaGActionPerformed(evt);
            }
        });

        jLabel12.setText("Hora:");

        jLabel13.setText("Ultima");

        jSeparator2.setOrientation(javax.swing.SwingConstants.VERTICAL);

        listaAlimentosG.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                listaAlimentosGMouseClicked(evt);
            }
        });
        jScrollPane5.setViewportView(listaAlimentosG);

        jLabel14.setText("Alimentos:");

        jLabel15.setText("Cantidad:");

        jLabel16.setText("Veces al dia:");

        jLabel17.setText("Frecuencia:");

        botonAlimentarGrupo.setText("Alimentar");
        botonAlimentarGrupo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonAlimentarGrupoActionPerformed(evt);
            }
        });

        areaCantidadG.setColumns(20);
        areaCantidadG.setRows(5);
        jScrollPane7.setViewportView(areaCantidadG);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(jLabel11)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(campoDiaG, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(jLabel12)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextField7))))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(96, 96, 96)
                        .addComponent(jLabel13)))
                .addGap(32, 32, 32)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel14)
                    .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(43, 43, 43)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(jLabel17)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(campoFrecuenciaG, javax.swing.GroupLayout.DEFAULT_SIZE, 86, Short.MAX_VALUE))
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(jLabel16)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(campoVecesDiaG, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(68, 68, 68))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel15)
                            .addComponent(botonAlimentarGrupo))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(2, 2, 2))))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel4Layout.createSequentialGroup()
                            .addGap(22, 22, 22)
                            .addComponent(jLabel13)
                            .addGap(18, 18, 18)
                            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel11)
                                .addComponent(campoDiaG, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(18, 18, 18)
                            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel12)
                                .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addComponent(jSeparator2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel14)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 153, Short.MAX_VALUE)))
                .addContainerGap(23, Short.MAX_VALUE))
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel16)
                    .addComponent(campoVecesDiaG, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel17)
                    .addComponent(campoFrecuenciaG, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jScrollPane7, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(29, Short.MAX_VALUE))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel15)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 72, Short.MAX_VALUE)
                        .addComponent(botonAlimentarGrupo))))
        );

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addGap(203, 203, 203)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(23, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        jButton1.setText("Aceptar");

        jButton2.setText("Cancelar");

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos tanque"));

        jLabel18.setText("Ubicacion:");

        jLabel19.setText("Capacidad:");

        jLabel20.setText("Material:");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel18)
                    .addComponent(campoUbicacion, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel19)
                    .addComponent(jLabel20)
                    .addComponent(campoMaterial, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(campoCapacidad, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(49, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addComponent(jLabel18)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(campoUbicacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel19)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(campoCapacidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(11, 11, 11)
                .addComponent(jLabel20)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(campoMaterial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(47, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel1)))
                            .addGroup(layout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(455, 455, 455)
                        .addComponent(jButton1)
                        .addGap(63, 63, 63)
                        .addComponent(jButton2)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(31, 31, 31)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 70, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void campoDiaGActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_campoDiaGActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_campoDiaGActionPerformed

    private void listaTanquesMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_listaTanquesMouseClicked
        Tanque tanque = null;
        tanque = tanques.get(listaTanques.getSelectedIndex());
        tanqueSeleccionado = tanque.getId();
        campoMaterial.setText(tanque.getMaterial());
        campoCapacidad.setText(Integer.toString(tanque.getCapacidad()));
        cargarAnimales(tanqueSeleccionado);
        cargarGrupos(tanqueSeleccionado);

    }//GEN-LAST:event_listaTanquesMouseClicked

    private void listaIndividuosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_listaIndividuosMouseClicked
        FechaAli fechaAli = null;
        Animal animal = null;
        animal = animales.get(listaIndividuos.getSelectedIndex());
        animalSeleccionado = animal.getId();
        fechaAli = persistFreddy.UltimaFechaAli(animalSeleccionado);
        
        campoDia.setText(fechaAli.getFecha().getDate()+"-"+(fechaAli.getFecha().
                getMonth()+1)+"-"+(fechaAli.getFecha().getYear()+1900));
        //campoDia.setText(Float.toString(fechaAli.getFecha().getTime()));
        System.out.println("ID ANIMAL: "+animalSeleccionado);
        cargarAlimentos(animalSeleccionado);

        
    }//GEN-LAST:event_listaIndividuosMouseClicked

    private void listaAlimentosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_listaAlimentosMouseClicked
        Alimento alimento = null;
        
        alimento = alimentos.get(listaAlimentos.getSelectedIndex());
        alimentoSeleccionado = alimento.getIdAlimento();
        espdie = persistFreddy.buscarEspDie(animalSeleccionado, alimentoSeleccionado);
        campoVecesDia.setText(Integer.toString(espdie.getVecesDia()));
        campoFrecuencia.setText(Integer.toString(espdie.getFrecuencia()));
        areaCantidad.setText(Integer.toString(espdie.getCantidad()));

    }//GEN-LAST:event_listaAlimentosMouseClicked

    private void listaGruposMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_listaGruposMouseClicked
        FechaAli fechaAli = null;
        Grupo grupo = null;
        especieSeleccionada = especies.get(listaGrupos.getSelectedIndex()).getIdEspecie();
        grupo = grupos.get(listaGrupos.getSelectedIndex());
        grupoSeleccionado = grupo.getId();
        cargarAlimentosG(grupoSeleccionado);
        fechaAli = persistFreddy.UltimaFechaAliG(grupoSeleccionado);
        campoDiaG.setText(fechaAli.getFecha().getDate()+"-"+fechaAli.getFecha().getMonth()+"-"+fechaAli.getFecha().getYear());
    }//GEN-LAST:event_listaGruposMouseClicked

    private void listaAlimentosGMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_listaAlimentosGMouseClicked
       Alimento alimento = null;
       
       alimento = alimentosG.get(listaAlimentosG.getSelectedIndex());
       alimentoGSeleccionado = alimento.getIdAlimento();
       espdieG = persistFreddy.buscarEspDieG(grupoSeleccionado, alimentoGSeleccionado);

       campoVecesDiaG.setText(Integer.toString(espdieG.getVecesDia()));
       campoFrecuenciaG.setText(Integer.toString(espdieG.getFrecuencia()));
       areaCantidadG.setText(Integer.toString(espdieG.getCantidad()));

    }//GEN-LAST:event_listaAlimentosGMouseClicked

    private void botonAlimentarAnimalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonAlimentarAnimalActionPerformed
        Date fecha = new Date();
        LoFe lofe = new LoFe();
        lotes = persistFreddy.buscarLoteAVencer(alimentoSeleccionado);
        FechaAli fechaAliAni = new FechaAli();

        fechaAliAni.setId(persistFreddy.UltimoFechaAli()+1);
        fechaAliAni.setIdAlimento(alimentoSeleccionado);
        fechaAliAni.setIdEspecie(persistEspecie.buscarEspecieAnimal(animalSeleccionado).getIdEspecie());
        fechaAliAni.setIdTanAni(persistFreddy.buscarTanAniAT(animalSeleccionado, tanqueSeleccionado));
        System.out.println("ID ESPECIE UPDA: "+fechaAliAni.getIdEspecie());
        System.out.println("ID ALIMENTO UPDA: "+fechaAliAni.getIdAlimento());
        System.out.println("ID tan ani UPDA: "+fechaAliAni.getIdTanAni());
        System.out.println("ID UPDA: "+fechaAliAni.getId());

        if(lotes.size()>1){
            lofe.setIdAlimento(alimentoSeleccionado);
            lofe.setIdFecha(fechaAliAni.getId());
            lofe.setIdLote(lotes.get(0).getIdLote());
            System.out.println("LOTE: "+ lotes.get(0).getPresentacion());
                if(espdie.getCantidad()>lotes.get(0).getCantidad()){
                    persistFreddy.restarCantidadLote(lotes.get(0).getIdLote(), lotes.get(0).getCantidad());
                    persistFreddy.insertFechaAliAni(fechaAliAni);
                    persistFreddy.insertLoFe(lofe);


                    FechaAli fechaAliAni2 = new FechaAli();

                    LoFe lofe2 = new LoFe();

                    ArrayList<Lote> lotes2 = null;
                    lotes2 = persistFreddy.buscarLoteAVencer(alimentoSeleccionado);
                    fechaAliAni2.setId(persistFreddy.UltimoFechaAli()+1);
                    fechaAliAni2.setIdAlimento(alimentoSeleccionado);
                    fechaAliAni2.setIdEspecie(persistEspecie.buscarEspecieAnimal(animalSeleccionado).getIdEspecie());
                    fechaAliAni2.setIdTanAni(persistFreddy.buscarTanAniAT(animalSeleccionado, tanqueSeleccionado));
                    lofe2.setIdAlimento(alimentoSeleccionado);
                    lofe2.setIdFecha(fechaAliAni2.getId());
                    lofe2.setIdLote(lotes2.get(0).getIdLote());

                    persistFreddy.restarCantidadLote(lotes2.get(0).getIdLote(), espdie.getCantidad()-lotes.get(0).getCantidad());
                    persistFreddy.insertFechaAliAni(fechaAliAni2);
                    persistFreddy.insertLoFe(lofe2);

                }else if (espdie.getCantidad()<lotes.get(0).getCantidad()){
                    persistFreddy.restarCantidadLote(lotes.get(0).getIdLote(), espdie.getCantidad());
                    persistFreddy.insertFechaAliAni(fechaAliAni);
                    persistFreddy.insertLoFe(lofe);
                }

        }else if(lotes.size()==1){
            lofe.setIdAlimento(alimentoSeleccionado);
            lofe.setIdFecha(fechaAliAni.getId());
            lofe.setIdLote(lotes.get(0).getIdLote());
            System.out.println("LOTE: "+ lotes.get(0).getPresentacion());
                if(espdie.getCantidad()>lotes.get(0).getCantidad()){
                    persistFreddy.restarCantidadLote(lotes.get(0).getIdLote(), lotes.get(0).getCantidad());
                    persistFreddy.insertFechaAliAni(fechaAliAni);
                    persistFreddy.insertLoFe(lofe);


                    FechaAli fechaAliAni2 = new FechaAli();

                    LoFe lofe2 = new LoFe();

                    ArrayList<Lote> lotes2 = null;
                    lotes2 = persistFreddy.buscarLoteAVencer(alimentoSeleccionado);
                    fechaAliAni2.setId(persistFreddy.UltimoFechaAli()+1);
                    fechaAliAni2.setIdAlimento(alimentoSeleccionado);
                    fechaAliAni2.setIdEspecie(persistEspecie.buscarEspecieAnimal(animalSeleccionado).getIdEspecie());
                    fechaAliAni2.setIdTanAni(persistFreddy.buscarTanAniAT(animalSeleccionado, tanqueSeleccionado));
                    lofe2.setIdAlimento(alimentoSeleccionado);
                    lofe2.setIdFecha(fechaAliAni2.getId());
                    lofe2.setIdLote(lotes2.get(0).getIdLote());

                    persistFreddy.restarCantidadLote(lotes2.get(0).getIdLote(), espdie.getCantidad()-lotes.get(0).getCantidad());
                    persistFreddy.insertFechaAliAni(fechaAliAni2);
                    persistFreddy.insertLoFe(lofe2);


                }else if (espdie.getCantidad()<lotes.get(0).getCantidad()){
                    persistFreddy.restarCantidadLote(lotes.get(0).getIdLote(), espdie.getCantidad());
                    persistFreddy.insertFechaAliAni(fechaAliAni);
                    persistFreddy.insertLoFe(lofe);
                }
        }
    }//GEN-LAST:event_botonAlimentarAnimalActionPerformed

    private void botonAlimentarGrupoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonAlimentarGrupoActionPerformed
        Date fecha = new Date();
        LoFe lofe = new LoFe();
        FechaAli fechaAliG = new FechaAli();
        lotesG = persistFreddy.buscarLoteAVencer(alimentoGSeleccionado);

        fechaAliG.setId(persistFreddy.UltimoFechaAli()+1);
        fechaAliG.setIdAlimento(alimentoGSeleccionado);
        fechaAliG.setIdEspecie(especieSeleccionada);
        fechaAliG.setIdGrupo(grupoSeleccionado);

        if(lotesG.size()>1){
            lofe.setIdAlimento(alimentoGSeleccionado);
            lofe.setIdFecha(fechaAliG.getId());
            lofe.setIdLote(lotesG.get(0).getIdLote());
            System.out.println("LOTE: "+ lotesG.get(0).getPresentacion());

            if(espdieG.getCantidad()>lotesG.get(0).getCantidad()){

                    persistFreddy.restarCantidadLote(lotesG.get(0).getIdLote(),lotesG.get(0).getCantidad());
                    persistFreddy.insertFechaAliG(fechaAliG);
                    persistFreddy.insertLoFe(lofe);

                    FechaAli fechaAliG3 = new FechaAli();

                    LoFe lofe3 = new LoFe();

                    ArrayList<Lote> lotes3 = null;
                    lotes3 = persistFreddy.buscarLoteAVencer(alimentoGSeleccionado);
                    fechaAliG3.setId(persistFreddy.UltimoFechaAli()+1);
                    fechaAliG3.setIdAlimento(alimentoGSeleccionado);
                    fechaAliG3.setIdEspecie(especieSeleccionada);
                    fechaAliG3.setIdGrupo(grupoSeleccionado);
                    lofe3.setIdAlimento(alimentoGSeleccionado);
                    lofe3.setIdFecha(fechaAliG3.getId());
                    lofe3.setIdLote(lotes3.get(0).getIdLote());

                    persistFreddy.restarCantidadLote(lotes3.get(0).getIdLote(),
                            (espdieG.getCantidad()*grupos.get(listaGrupos.getSelectedIndex()).getEstimado()-lotesG.get(0).getCantidad()));
                    persistFreddy.insertFechaAliG(fechaAliG3);
                    persistFreddy.insertLoFe(lofe3);

            }else if (espdie.getCantidad()<lotesG.get(0).getCantidad()){
                persistFreddy.restarCantidadLote(lotesG.get(0).getIdLote(), espdieG.getCantidad()*grupos.get(listaGrupos.getSelectedIndex()).getEstimado());
                persistFreddy.insertFechaAliG(fechaAliG);
                persistFreddy.insertLoFe(lofe);
            }
            
        }else if(lotesG.size()==1){
            lofe.setIdAlimento(alimentoGSeleccionado);
            lofe.setIdFecha(fechaAliG.getId());
            lofe.setIdLote(lotesG.get(0).getIdLote());
            System.out.println("LOTE: "+ lotesG.get(0).getPresentacion());
            if(espdieG.getCantidad()>lotesG.get(0).getCantidad()){

                    persistFreddy.restarCantidadLote(lotesG.get(0).getIdLote(),lotesG.get(0).getCantidad());
                    persistFreddy.insertFechaAliG(fechaAliG);
                    persistFreddy.insertLoFe(lofe);

                    FechaAli fechaAliG3 = new FechaAli();

                    LoFe lofe3 = new LoFe();

                    ArrayList<Lote> lotes3 = null;
                    lotes3 = persistFreddy.buscarLoteAVencer(alimentoGSeleccionado);
                    fechaAliG3.setId(persistFreddy.UltimoFechaAli()+1);
                    fechaAliG3.setIdAlimento(alimentoGSeleccionado);
                    fechaAliG3.setIdEspecie(especieSeleccionada);
                    fechaAliG3.setIdGrupo(grupoSeleccionado);
                    lofe3.setIdAlimento(alimentoGSeleccionado);
                    lofe3.setIdFecha(fechaAliG3.getId());
                    lofe3.setIdLote(lotes3.get(0).getIdLote());

                    persistFreddy.restarCantidadLote(lotes3.get(0).getIdLote(), 
                            (espdieG.getCantidad()*grupos.get(listaGrupos.getSelectedIndex()).getEstimado()-lotesG.get(0).getCantidad()));
                    persistFreddy.insertFechaAliG(fechaAliG3);
                    persistFreddy.insertLoFe(lofe3);

            }else if (espdie.getCantidad()<lotesG.get(0).getCantidad()){
                persistFreddy.restarCantidadLote(lotesG.get(0).getIdLote(), espdieG.getCantidad()*grupos.get(listaGrupos.getSelectedIndex()).getEstimado());
                persistFreddy.insertFechaAliG(fechaAliG);
                persistFreddy.insertLoFe(lofe);
            }
            
            
        }
    }//GEN-LAST:event_botonAlimentarGrupoActionPerformed

    public void cargarTanques(){
        modeloTanques.clear();
        listaTanques.setModel(modeloTanques);
        tanques = persistTanque.todosLosTanques();
        for (int i = 0; i < tanques.size(); i++) {
            modeloTanques.addElement(tanques.get(i).getId());
        }
    }

    public void cargarAnimales(int idTanque){
        modeloIndividuos.clear();
        listaIndividuos.setModel(modeloIndividuos);
        animales = persistFreddy.individuosPorTanque(idTanque);
        for (int i = 0; i < animales.size(); i++) {
            modeloIndividuos.addElement(animales.get(i).getNombre());
        }
    }

    public void cargarAlimentos(int idAnimal){
        modeloAlimentos.clear();
        listaAlimentos.setModel(modeloAlimentos);
        alimentos = persistFreddy.alimentosPorAnimal(idAnimal);
        for (int i = 0; i < alimentos.size(); i++) {
            modeloAlimentos.addElement(alimentos.get(i).getNombre());
        }
    }

    public void cargarAlimentosG(int idGrupo){
        modeloAlimentosG.clear();
        listaAlimentosG.setModel(modeloAlimentosG);
        alimentosG = persistFreddy.alimentosPorGrupo(idGrupo);
        for (int i = 0; i < alimentosG.size(); i++) {
            modeloAlimentosG.addElement(alimentosG.get(i).getNombre());
        }
    }

    public void cargarGrupos(int idTanque){
        modeloGrupos.clear();
        listaGrupos.setModel(modeloGrupos);
        especies = persistEspecie.buscarEspecieGrupoTanque(idTanque);
        grupos = persistEspecie.buscarGruposPorTanque(idTanque);
        for (int i = 0; i < especies.size(); i++) {
            modeloGrupos.addElement(especies.get(i).getNombreEsp());
        }
    }
    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new VentanaAlimentacion().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextArea areaCantidad;
    private javax.swing.JTextArea areaCantidadG;
    private javax.swing.JButton botonAlimentarAnimal;
    private javax.swing.JButton botonAlimentarGrupo;
    private javax.swing.JTextField campoCapacidad;
    private javax.swing.JTextField campoDia;
    private javax.swing.JTextField campoDiaG;
    private javax.swing.JTextField campoFrecuencia;
    private javax.swing.JTextField campoFrecuenciaG;
    private javax.swing.JTextField campoHoraAnimal;
    private javax.swing.JTextField campoMaterial;
    private javax.swing.JTextField campoUbicacion;
    private javax.swing.JTextField campoVecesDia;
    private javax.swing.JTextField campoVecesDiaG;
    private javax.swing.JDialog dialogAlimento;
    private javax.swing.JDialog dialogAlimentoG;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JScrollPane jScrollPane7;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JTextField jTextField7;
    private javax.swing.JList listaAlimentos;
    private javax.swing.JList listaAlimentosG;
    private javax.swing.JList listaGrupos;
    private javax.swing.JList listaIndividuos;
    private javax.swing.JList listaTanques;
    // End of variables declaration//GEN-END:variables

}
